<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateAdminUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('admin_users')) {
            Schema::create('admin_users', function (Blueprint $table) {
                $table->id();
                $table->integer('parent_id')->comment('上级管理员 ID');
                $table->string('phone')->unique();
                $table->string('name', 32)->nullable();
                $table->string('email', 64)->nullable();
                $table->string('password');
                $table->enum('is_super', ['y', 'n'])->default('n')->comment('越权超管');
                $table->string('avatar')->default('/images/avatar/default.png');
                $table->string('qrcode')->nullable()->comment('小程序码');
                $table->enum('sex', ['男', '女'])->default('男');
                $table->string('introduction')->nullable()->comment('简介');
                $table->timestamp('phone_verified_at')->nullable();
                $table->timestamp('sign_time')->nullable()->comment('登录时间');
                $table->string('sign_ip', 15)->nullable()->comment('登录IP');
                $table->integer('sign_count')->default(0)->comment('登录次数');
                $table->timestamp('register_time')->nullable();
                $table->string('register_ip', 15)->nullable();
                $table->enum('status', ['normal', 'ban'])->default('ban');
                $table->string('openid',  128)->nullable()->comment('OpenID');
                $table->string('unionid', 128)->nullable()->comment('Union 第三方 ID');
                $table->rememberToken();
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `admin_users` comment '管理员表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
    }
}
